
using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Entity;

namespace Data
{
	public class DAActividadesPlan
	{

        public static DataTable ListarActividadesxPlan(string strCodPlanAdmision)
        {
            SqlDatabase sqlActividadesxPlan = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlActividadesxPlan.GetStoredProcCommand("plst_ActividadesxPlan");
            sqlActividadesxPlan.AddInParameter(dbCmd, "@strCodPlanAdmision", DbType.String, strCodPlanAdmision);
            return sqlActividadesxPlan.ExecuteDataSet(dbCmd).Tables[0];
        }

        public static void RegistrarActividadPlan(BEActividadesPlan oBEActividadPlan)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);

            using (DbConnection connection = sqlClient.CreateConnection())
            {
                connection.Open();
                DbTransaction transaction = connection.BeginTransaction();
                try
                {
                    DbCommand dbCmd = sqlClient.GetStoredProcCommand("pmnt_ActividadPlan");

                    sqlClient.AddInParameter(dbCmd, "@strCodPlanAdmision", DbType.String, oBEActividadPlan.CodPlanAdmision);
                    sqlClient.AddInParameter(dbCmd, "@strCodActividad", DbType.String, oBEActividadPlan.CodActividad);
                    //sqlClient.AddInParameter(dbCmd, "@dtFecActividad", DbType.Date, oBEActividadPlan.FecActividad);
                    sqlClient.AddInParameter(dbCmd, "@strDireccion", DbType.String, oBEActividadPlan.Direccion);
                    sqlClient.AddInParameter(dbCmd, "@intEstado", DbType.Int32, oBEActividadPlan.Estado);
                    //sqlClient.AddInParameter(dbCmd, "@dtFecCierre", DbType.Date, oBEActividadPlan.FecCierre);
                    sqlClient.AddInParameter(dbCmd, "@strUsuCreacion", DbType.String, oBEActividadPlan.UsuCreacion);
                    sqlClient.AddInParameter(dbCmd, "@strUsuModificacion", DbType.String, oBEActividadPlan.UsuModificacion);
                    sqlClient.ExecuteNonQuery(dbCmd);
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw new Exception(ex.Message);
                }
            }
        }

        public static DataTable QuitarActividadesPlan(BEActividadesPlan oBEActividadesPlan)
        {
            SqlDatabase sql = new SqlDatabase(Configuracion.GetConnection);
            using (DbConnection connection = sql.CreateConnection())
            {
                connection.Open();
                DbTransaction transaction = connection.BeginTransaction();
                try
                {
                    DbCommand dbCmd = sql.GetStoredProcCommand("pact_ActividadPlan");

                    sql.AddInParameter(dbCmd, "@intId_PlanActFec", DbType.Int16, oBEActividadesPlan.Id_PlanActFec);
                    sql.AddInParameter(dbCmd, "@strUsuModificacion", DbType.String, oBEActividadesPlan.UsuModificacion);
                    DataTable dtRequisitosPlan = sql.ExecuteDataSet(dbCmd).Tables[0];
                    transaction.Commit();
                    return dtRequisitosPlan;
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw new Exception(ex.Message);
                }
            }
        }
    }
}
      